<?php

class Admin_PatientsController extends Admin_AbstractController
{
	
    public function init()
    {
    	parent::init();
    	$this->autoSwitchContext('json','json');
    }

    public function indexAction()
    {    	
    	$patientsModel = new Itc_Model_DbTable_Patient();

    	$params = $this->request->getParams();
    	
    	$data = $patientsModel->getGridData($params,$this->view);
    }

	public function searchAction()
	{
		$patientsModel = new Itc_Model_DbTable_Patient();

		$params = $this->request->getParams();

		$data = $patientsModel->getGridData($params,$this->view,array('id','PName'=>'CONCAT(f_name,l_name)'));
	}
    
	public function editAction()
    {
        $data = $this->request->getParams();
        $patientsModel = new Itc_Model_DbTable_Patient();

        try {
            $patientsModel->save($data);
            $this->view->success = true;
        } catch (Exception $e) {
            $this->view->success = false;
            $this->view->errors = array($e->getMessage());
        }
    }
    
	public function deleteAction()
    {
		$id = $this->request->getParam('id', '');
		$patientsModel = new Itc_Model_DbTable_Patient();

		try {
			$patientsModel->deleteById($id);
			$this->view->success = true;
		} catch (Exception $e) {
			$this->view->success = false;
			$this->view->error = array($e->getMessage());
		}
    }
}

